package com.zhonghui.modlules.product.eshopMapper;

import com.zhonghui.common.eshopMapper.CoreMapper;
import com.zhonghui.modlules.product.eshopVo.StoreProductAttrValue;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface StoreProductAttrValueMapper extends CoreMapper<StoreProductAttrValue> {
    @Update({"update store_product_attr_value set stock=stock+#{num}, sales=sales-#{num} where product_id=#{productId} and `unique`=#{unique}"})
    int incStockDecSales(@Param("num") Integer num, @Param("productId") Long productId, @Param("unique") String unique);

    @Update({"update store_product_attr_value set stock=stock+#{num}, pink_stock=pink_stock+#{num}, sales=sales-#{num} where product_id=#{productId} and `unique`=#{unique}"})
    int incCombinationStockDecSales(@Param("num") Integer num, @Param("productId") Long productId, @Param("unique") String unique);

    @Update({"update store_product_attr_value set stock=stock+#{num},seckill_stock=seckill_stock+#{num}, sales=sales-#{num} where product_id=#{productId} and `unique`=#{unique}"})
    int incSeckillStockDecSales(@Param("num") Integer num, @Param("productId") Long productId, @Param("unique") String unique);

    @Update({"update store_product_attr_value set stock=stock-#{num}, sales=sales+#{num} where product_id=#{productId} and `unique`=#{unique} and stock >= #{num}"})
    int decStockIncSales(@Param("num") Integer num, @Param("productId") Long productId, @Param("unique") String unique);

    @Update({"update store_product_attr_value set stock=stock-#{num}, pink_stock=pink_stock-#{num} ,sales=sales+#{num} where product_id=#{productId} and `unique`=#{unique} and stock >= #{num} and pink_stock>=#{num}"})
    int decCombinationStockIncSales(@Param("num") Integer num, @Param("productId") Long productId, @Param("unique") String unique);

    @Update({"update store_product_attr_value set stock=stock-#{num}, seckill_stock=seckill_stock-#{num},sales=sales+#{num} where product_id=#{productId} and `unique`=#{unique} and stock >= #{num} and seckill_stock>=#{num}"})
    int decSeckillStockIncSales(@Param("num") Integer num, @Param("productId") Long productId, @Param("unique") String unique);
}

